<!--
 * @Author: your name
 * @Date: 2020-08-22 01:51:42
 * @LastEditTime: 2020-08-27 19:38:57
 * @LastEditors: 郝汉森
 * @Description: In User Settings Edit
 * @FilePath: \exam-list\src\components\checkpaper\PaperDetail.vue
-->
<template>
  <div>
    <h2>添加试题</h2>
    <el-card>
      <p>题目信息</p>
      <el-row>
        <p>题干</p>
        <el-input placeholder="请输入题目标题，不超过20个字" v-model="test.title"></el-input>
      </el-row>
      <el-row>
        <p>题目主题</p>
        <editor-bar v-model="test.questions_stem" :isClear="isClear"></editor-bar>
      </el-row>
      <el-row>
        <p>请选择考试类型</p>
        <el-select v-model="test.exam_id" clearable placeholder="请选择">
          <el-option
            v-for="item in examType"
            :key="item.exam_id"
            :label="item.exam_name"
            :value="item.exam_id">
          </el-option>
        </el-select>
      </el-row>
      <el-row>
        <p>请选择课程类型</p>
        <el-select v-model="test.subject_id" clearable placeholder="请选择">
          <el-option
            v-for="item in subject"
            :key="item.subject_id"
            :label="item.subject_text"
            :value="item.subject_id">
          </el-option>
        </el-select>
      </el-row>
      <el-row>
        <p>请选择题目类型</p>
        <el-select v-model="test.questions_type_id" clearable placeholder="请选择">
          <el-option
            v-for="item in questionsType"
            :key="item.questions_type_id"
            :label="item.questions_type_text"
            :value="item.questions_type_id">
          </el-option>
        </el-select>
      </el-row>
      <el-row>
        <p>答案信息</p>
        <editor-bar v-model="test.questions_answer" :isClear="isClear"></editor-bar>
      </el-row>
      <el-button type="primary" @click="submitAdd">提交</el-button>
    </el-card>
    
  </div>
</template>

<script>
import EditorBar from './components/editoritem'
import {mapState,mapActions} from "vuex"
export default {
  components: { EditorBar },
  data() {
    return {
      isClear: false,
      test:this.$route.query.data
    }
  },
  created() {
    this.getQuestionsTypeApi()
    this.getSubjectApi()
    this.getExamTypeApi()
  },
  computed: {
    ...mapState('Question', ['questionsType','subject','examType']),
  },
  methods: {
    ...mapActions('Question', ['getSubjectApi','getQuestionsTypeApi','getExamTypeApi','editQuestionsApi']),
    submitAdd(){
      this.$confirm('确定要修改试题吗, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.editQuestionsApi(this.test)
          // let res=this.editQuestionsApi(this.test)
          // if(res.code===1){
          //   this.$message({
          //     type: 'success',
          //     message: '修改成功!'
          //   });
          // }else{
          //    this.$message.error('修改失败')
          // }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消修改'
          });          
        });
    }
  }
}
</script>

<style>
.el-row{
  margin-bottom: 32px;
}
p{
  margin-bottom: 10px;
}
</style>

